package com.item.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class jdbc {
    public static void main(String[] args) throws Exception {
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接：如果连接的是本机mysql并且端口是默认的3306 可以简化书写
        // url="jdbc:mysql://127.0.0.1:3306/db1";
        String url="jdbc:mysql:///db1?useSSL=false";
        String username="root";
        String password="";
        Connection conn = DriverManager.getConnection(url, username, password);

        //3.定义
        String sql="update account set money =2000 where id=1";
        //4.获取执行sql的对象Statement
        Statement stmt = conn.createStatement();
        //5.执行sql
        int count=stmt.executeUpdate(sql);//受影响的行数
        //6.处理结果
        System.out.println(count);
        //7.释放资源
        stmt.close();
        conn.close();
    }
}
